package org.example.controller;

import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

@RestController
@Slf4j
public class DemoController {

    @GetMapping("/ok")
    public String ok() throws Exception{
        //异步实现
        log.info("--------started---------");
        ExecutorService executorService = new ThreadPoolExecutor(8, 16, 60L, TimeUnit.SECONDS,
                new LinkedBlockingQueue<>(100));
        executorService.execute(()->{
            try {
                TimeUnit.SECONDS.sleep(5);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            System.out.println(Thread.currentThread().getName()+"执行完毕");

        });
        executorService.shutdown();
        log.info("--------stop---------");
    return "ok";
    }
}
